home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-06 | 3.1 KB | 131 lines | [TEXT/MPCC] |
- # catch.s - C++ 'catch' support routines for Metrowerks C++ for PowerPC
- #
- # Copyright © 1995 metrowerks inc. All Rights Reserved.
- #
- #
- # THEORY OF OPERATION
- #
- # The runtime support routines __setup_catchregbuffer() and __catch_jump() support
- # the C++ exception handling facilities.
- #
- # __setup_catchregbuffer() captures the state of the program in a CatchRegBuffer
- # data structure (similar to a jmp_buf) which has the following C definition:
- #
- # typedef struct CatchRegBuffer {
- # unsigned long ldc; // 0: (not used)
- # unsigned long PC; // 4: (not used)
- # unsigned long CR; // 8: saved CR
- # unsigned long SP; // 12: saved SP
- # unsigned long RTOC; // 16: saved RTOC
- # unsigned long GPRs[19]; // 20: saved r13-r31
- # double FPRs[18]; // 96: saved fp14-fp31
- # double FPSCR; //240: saved FPSCR
- # } *CatchRegBuffer;
- #
- # __catch_jump() restores the state and transfers to an exception handler with the
- # appropriate registers, stack, TOC, etc.
- #
- # These routines are defined as follows:
- #
- # void __setup_catchregbuffer(CatchRegBuffer *crp);
- # void __catch_jump(CatchRegBuffer *crp,void *pc);
- #
- #
- # BUILD INSTRUCTIONS
- #
- # To assemble this file:
- #
- # ppcasm catch.s -o catch.o
- #
- # The object file catch.o can be added directly to any CodeWarrior™ project.
- #
-
- dialect powerpc
-
- #
- # Public Data
- #
- csect __setup_catchregbuffer{DS}
- export __setup_catchregbuffer{DS}
- dc.l .__setup_catchregbuffer{PR}
- dc.l TOC{TC0}
-
- csect __catch_jump{DS}
- export __catch_jump{DS}
- dc.l .__catch_jump{PR}
- dc.l TOC{TC0}
-
- #
- # TOC pointers
- #
- toc
-
-
- # __setup_catchregbuffer - save non-volatile registers
- #
- # On entry R3 points to a CatchRegBuffer struct.
- #
- csect .__setup_catchregbuffer{PR}
- export .__setup_catchregbuffer{PR}
- mfcr r6
- stw SP,12(r3) # save SP
- stw RTOC,16(r3) # save RTOC
- stw r6,8(r3) # save CR
- stmw r13,20(r3) # save r13-r31
- mffs fp0
- stfd fp14,96(r3) # save fp14-fp31
- stfd fp15,104(r3)
- stfd fp16,112(r3)
- stfd fp17,120(r3)
- stfd fp18,128(r3)
- stfd fp19,136(r3)
- stfd fp20,144(r3)
- stfd fp21,152(r3)
- stfd fp22,160(r3)
- stfd fp23,168(r3)
- stfd fp24,176(r3)
- stfd fp25,184(r3)
- stfd fp26,192(r3)
- stfd fp27,200(r3)
- stfd fp28,208(r3)
- stfd fp29,216(r3)
- stfd fp30,224(r3)
- stfd fp31,232(r3)
- stfd fp0,240(r3) # save FPSCR
- blr
-
-
- # __catch_jump - restore non-volatile registers and jump to catch-block
- #
- # On entry R3 points to a CatchRegBuffer struct and R4 contains the destination address.
- #
- csect .__catch_jump{PR}
- export .__catch_jump{PR}
- lwz r6,8(r3)
- mtctr r4 # destination address
- mtcrf 255,r6 # restore CR
- lwz SP,12(r3) # restore SP
- lwz RTOC,16(r3) # restore RTOC
- lmw r13,20(r3) # restore r13-r31
- lfd fp14,96(r3) # restore fp14-fp31
- lfd fp15,104(r3)
- lfd fp16,112(r3)
- lfd fp17,120(r3)
- lfd fp18,128(r3)
- lfd fp19,136(r3)
- lfd fp20,144(r3)
- lfd fp21,152(r3)
- lfd fp22,160(r3)
- lfd fp23,168(r3)
- lfd fp24,176(r3)
- lfd fp25,184(r3)
- lfd fp26,192(r3)
- lfd fp27,200(r3)
- lfd fp28,208(r3)
- lfd fp29,216(r3)
- lfd fp30,224(r3)
- lfd fp0,240(r3)
- lfd fp31,232(r3)
- mtfsf 255,fp0 # restore FPSCR
- bctr
-